package com.ftg.learn.chapter17.expand.question;

/**
 * @author KangJx
 * @date 2021/8/17
 */
public class MyLinkedAccess {

    //终止方法
    private StringBuilder target;

    public String getTarget(){
        if(this.target == null){
            return null;
        }
        return this.target.toString();
    }

    /**
     * 链式方法
     * @param str
     * @return
     */
    public MyLinkedAccess add(String str){
        if(null == this.getTarget()){
            this.target = new StringBuilder();
        }
//        target += str;
        target.append(str);
        //this表示本身的所有实例对象
        return this;
    }

    public static void main(String[] args) {
        MyLinkedAccess mla = new MyLinkedAccess();
        //字符串进行相加操作
        //链式访问
        System.out.println(mla.getTarget());
        //链式调用  链式访问
        System.out.println(mla.add("k").add("j").add("x").add("帅").getTarget());
    }

}
